﻿// ***********************************************************************
// Project			: Micua
// Assembly         : Micua.BLL
// Author           : iceStone
// Created          : 2013-11-23 21:59
//
// Last Modified By : iceStone
// Last Modified On : 2013-11-23 22:11
// ***********************************************************************
// <copyright file="PostService.cs" company="Wedn.Net">
//     Copyright (c) Wedn.Net. All rights reserved.
// </copyright>
// <summary>发表物 服务类拓展.</summary>
// ***********************************************************************

using System;
using System.Linq;
using Micua.Core.Caching.Interception;
using Micua.Model;
using Micua.Model.Enum;
using Micua.Model.Extension;

namespace Micua.BLL
{
    /// <summary>
    /// 发表物 服务类拓展.
    /// </summary>
    /// <remarks>
    ///  2013-11-23 22:11 Created By iceStone
    /// </remarks>
    public partial class PostService
    {
        #region 获取文章前后 +Around<Post> GetPostAround(Post item)
        /// <summary>
        /// 获取文章前后
        /// </summary>
        /// <remarks>
        ///  2013-11-23 22:11 Created By iceStone
        /// </remarks>
        /// <param name="item">当前文章</param>
        /// <returns>Around{Post}.</returns>
        public Around<Post> GetPostAround(Post item)
        {
            //var posts =
            //    DAO.Select(
            //        i =>
            //            i.Id == DAO.Select(p => p.Id > item.Id).Min(p => p.Id) ||
            //            i.Id == DAO.Select(p => p.Id < item.Id).Max(p => p.Id));
            //var prevQuery = DAO.Select(p => p.Id < item.Id && p.Type == (short)PostType.Article && p.Status >= (short)PostStatus.Default);
            //var nextQuery = DAO.Select(p => p.Id > item.Id && p.Type == (short)PostType.Article && p.Status >= (short)PostStatus.Default);
            //var prevId = prevQuery.Max(p => p.Id);
            //var nextId = nextQuery.Min(p => p.Id);
            var prev = Repository.Query(p => p.Id < item.Id && p.Type == (byte)PostType.Article && p.Status == (byte)PostStatus.Default).OrderByDescending(p => p.Id).FirstOrDefault();
            var next = Repository.Query(p => p.Id > item.Id && p.Type == (byte)PostType.Article && p.Status == (byte)PostStatus.Default).OrderBy(p => p.Id).FirstOrDefault();
            return new Around<Post>
            {
                Previous = prev,
                Next = next
            };
        }
        #endregion
        [CachingCallResult(300)]
        public string GetSomthing(int page)
        {
            return Guid.NewGuid().ToString();
        }
    }
}